package com.ccp.dev.qbdms.enums;

import com.ccp.dev.core.util.CollectionUtil;

import java.util.List;

/**
 * Created by zzy on 2020/7/28.
 *
 * @Author zzy
 * @Date 2020/7/28
 * @describe 场所级状态码对应院级状态码,用于集中部署时过滤数据以及状态回显
 */
public enum PlantLevelStateCodeEnum {
    /**待上报*/
    DSB("4","待上报",CollectionUtil.newList()),
    /**报院审批中*/
    SPZ("5","报院审批中",CollectionUtil.newList()),
    /**报院审批未通过*/
    WTG("6","报院审批未通过",CollectionUtil.newList()),
    /**报院中*/
    BYZ("7","报院中",CollectionUtil.newList()),
    /**报院成功  对应院级一系列状态码,系统等级为场所级时出现这些状态码表示该数据状态就是报院成功 */
    BYCG("8","报院成功",CollectionUtil.newList("12","13","14","15","16","17","18","19","20","25","26","27","31","33","29","21","22","23","24","28","32")),
    /**报院失败*/
    BYSB("9","报院失败",CollectionUtil.newList()),
    /**退回待修改*/
    THDXG("10","退回待修改",CollectionUtil.newList()),
    /**无需上报,院级退回*/
    WXSB("11","无需上报",CollectionUtil.newList());


    /**
     * 获取全部的状态码
     *  @auth zzy
     * @return
     */
    public static List<String> getAllCode(){
        List<String> list = CollectionUtil.newList();
        for (PlantLevelStateCodeEnum value : PlantLevelStateCodeEnum.values()) {
            list.add(value.code);
            list.addAll(value.relatedCode);
        }
        return list;
    }

    /**
     * 根据状态code获取状态name
     * @param code
     * @return
     */
    public static String getNameByCode(String code){
        for (PlantLevelStateCodeEnum e : PlantLevelStateCodeEnum.values()) {
            if (e.code.equals(code)) {
                return e.name;
            }
            if (e.relatedCode.contains(code)) {
                return e.name;
            }
        }
        return "";
    }

    /**
     * 根据关联code查找对应的状态code
     * @param code
     * @return
     */
    public static String getCodeByRelatedCode(String code){
        for (PlantLevelStateCodeEnum e : PlantLevelStateCodeEnum.values()) {
            if (e.code.equals(code)) {
                return e.code;
            }
            if (e.relatedCode.contains(code)) {
                return e.code;
            }
        }
        return "";
    }

    /**
     * 根据code查找对应的relatedcode
     * @author zzy
     * @param code
     * @return
     */
    public static List<String> getRelatedCodeByCode(String code){
        List<String> list = CollectionUtil.newList();
        for (PlantLevelStateCodeEnum e : PlantLevelStateCodeEnum.values()) {
            if (e.getCode().equals(code)) {
                list.addAll(e.getRelatedCode());
                break;
            }
        }
        return list;
    }


    /**状态码*/
    private String code;
    /**状态名称*/
    private String name;
    /**对应上级状态码*/
    private List<String> relatedCode;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getRelatedCode() {
        return relatedCode;
    }

    public void setRelatedCode(List<String> relatedCode) {
        this.relatedCode = relatedCode;
    }

    private PlantLevelStateCodeEnum(String code, String name, List<String> relatedCode) {
        this.code = code;
        this.name = name;
        this.relatedCode = relatedCode;
    }

}
